package com.hqyj.controller;

import com.hqyj.pojo.UserInfo;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description
 * @Autor 伍军
 * @Date 2022/10/11 10:41
 * @Version 1.0
 **/
@RestController
@RequestMapping("/hello")
public class HelloController {

    //注入mq 服务对象
    @Autowired
    RabbitTemplate rabbitTemplate;

    //演示发送消息用map
    @GetMapping("/login")
    public String login(String name, String pwd){

        //第一步：封装消息
        Map<String,Object> map = new HashMap<>();
        map.put("name",name);
        map.put("pwd",pwd);
        //发送消息
        rabbitTemplate.convertAndSend("simpleExchage","directRout",map);
        return "success";

    }
    //演示发送消息用pojo类
    @GetMapping("/login01")
    public String login(UserInfo userInfo){

        //发送消息
        rabbitTemplate.convertAndSend("simpleExchage","directRout",userInfo);
        return "success";

    }
    //演示发送消息，获取返回值，这个返回值是消费者服务的返回值
    @GetMapping("/login02")
    public String login02(UserInfo userInfo){

        //发送消息
        return  rabbitTemplate.convertSendAndReceive("simpleExchage","directRout",userInfo)+"";

    }

}
